module MC.View {
	export class Zhaopin {
		public constructor() {
			this.init();
		}
		private list: MC.Page;
		private init() {
			this.list = new MC.Page("#jobPage", 'myzhaopin', {},
				(resData: any, page: any) => {
					if (page == 0 && resData.length == 0) {
						var h = '';
						h += '<table class="toJobShow">';
						h += '<tr>';
						h += '<td colspan="2" style="text-align:center;">没有信息</td>';
						h += '</tr>';
						h += '</table>';
						$('#jobDetail').html(h);
						$('.btn').hide();
						return;
					} else {
						this.jobs_ul('#jobDetail .jobs_ul', resData);
					}
				});
			this.list.init();
			this.onClick();
		}
		private jobs_ul(jselect: string, list: any) {
			let jq = $(jselect);
			for (let i = 0; i < list.length; i++) {
				let obj = list[i];
				let li = `<li class="jobli">
                    <div jobid="`+ obj.id + `" class="jcon status_` + obj.status + `">
                        <a class="jobli_a" href="/h5/index/job/jobShow.html?jobId=`+ obj.id + `"><div class="top clearfix">
                            <span class="jobName">`+ obj.jobName + `</span>
                            <span class="emolument">`+ obj.emolument + `</span>
                        </div></a>
                        <p class="desc skill">`+ obj.address + `</p>
                        <div class="tablist">
                            <a class="tabone">`+ obj.education + `</a>
							<a class="tabone">年龄`+ MC.API.tihuan(obj.age_range, ',', '-') + `</a>
                        </div>
                        
						 <div class="userinfo clearfix">
						  <a class="jobli_a headdiv" href="/h5/index/job/jobShow.html?jobId=`+ obj.id + `">
                             	<img src="`+ obj.head + `"  class="head" /> 
							</a>
							<div class="jobli_a usernameDiv" href="/h5/index/job/jobShow.html?jobId=`+ obj.id + `"> 
										<a class="company_name" href="/h5/index/job/jobShow.html?jobId=`+ obj.id + `">`+ obj.company_name + `</a>
										<a class="uname" href="/h5/index/job/jobShow.html?jobId=`+ obj.id + `">`+ obj.uname + `</a>  
										<span class="status_src">`+ obj.status_src + `</span>  
							</div>
                        </div>
						
						<div class="kbuttonDiv clearfix"> 
								<div class="kbuttonCon">
									<a class="button fabu">发布</a>
									<a class="button xiajia">下架</a>
									<a class="buttonred button delete">删除</a>
								</div>
						</div>

                    </div>
                </li>`;
				jq.append(li);
			}
		}



		private onClick() {
			let mthis = this;
			$('#jobDetail').on('click', '.kbuttonCon .fabu', function () {
				let one = $(this).parents('[jobid]');
				let jobid = one.attr('jobid');
				MC.msg.confirm('是否确定发布该岗位?', () => {
					MC.apiD('upJobStatus', { type: 'fabu', id: jobid }, () => {
						location.reload();
					});
				});
				console.log(jobid, '发布');
			});
			$('#jobDetail').on('click', '.kbuttonCon .xiajia', function () {
				let one = $(this).parents('[jobid]');
				let jobid = one.attr('jobid');
				MC.msg.confirm('是否确定下架该岗位?', () => {
					MC.apiD('upJobStatus', { type: 'xiajia', id: jobid }, () => {
						location.reload();
					});
				});
				console.log('下架');
			});
			$('#jobDetail').on('click', '.kbuttonCon .delete', function () {
				let one = $(this).parents('[jobid]');
				let jobid = one.attr('jobid');
				MC.msg.confirm('是否确定删除该岗位?', () => {
					MC.apiD('upJobStatus', { type: 'delete', id: jobid }, () => {
						location.reload();
					});
				});
				console.log('删除');
			});
		}
	}

}